When tracking which elements were clicked e.target.id is sometimes empty [migrated]

Posted by Ivan on Pro Webmasters See other posts from Pro Webmasters or by Ivan
Published on 2012-03-25T21:07:15Z Indexed on 2012/03/25 23:41 UTC
Read the original article Hit count: 242

Filed under:
|

I am trying to test the following JavaScript code, which is meant to keep track of the timing of user responses on a multiple choice survey:

document.onclick = function(e) {

var event = e || window.event;    
var target = e.target || e.srcElement;

//time tracking 
var ClickTrackDate = new Date;
var ClickData = ""; 
ClickData = target.id + "=" + ClickTrackDate.getUTCHours() + ":" + ClickTrackDate.getUTCMinutes() + ":" + ClickTrackDate.getUTCSeconds() +";";

document.getElementById("txtTest").value += ClickData;
alert(target.id); // for testing
}

Usually target.id equals to the the id of the clicked element, as you would expect, but sometimes target.id is empty, seemingly at random, any ideas?

© Pro Webmasters or respective owner

Related posts about JavaScript

Related posts about click-tracking